#include <stdio.h>
#include <stdlib.h>
typedef struct Node
{
    int age;
    struct Node *next;
} Node;

// 单指针传参, 尝试修改结构体地址
Node *ModifyAddress(Node *p)
{
    printf("ModifyAddress():\n");

    printf("数据: p.age = %d\n", p->age);
    printf("地址: p = %x, p->next = %x\n", p, p->next);
    printf("形参指针变量p的地址 = %x\n\n", &p);

    // 尝试为指针重新分配地址，并修改原本结构体内部数据
    p = (Node *)malloc(sizeof(Node));
    p->age = 4;
    p->next = NULL;

    printf("数据: p.age = %d\n", p->age);
    printf("地址: p = %x, p->next = %x\n", p, p->next);
    printf("形参指针变量p的地址 = %x\n\n", &p);

    // 返回修改后的结构体指针p
    return p;
}

int main()
{
    Node p;
    p.age = 1;
    p.next = NULL;

    printf("main():\n");
    printf("数据: p.age = %d\n", p.age);
    printf("地址: p = %x, p->next = %x\n\n", &p, p.next);

    Node *new_p = ModifyAddress(&p);

    printf("main():\n");
    printf("数据: p.age = %d\n", p.age);
    printf("地址: p = %x, p->next = %x\n", &p, p.next);

    printf("数据: new_p.age = %d\n", new_p->age);
    printf("地址: new_p = %x, new_p->next = %x\n\n", new_p, new_p->next);

    return 0;
}
